<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>
        layui在线调试
    </title>
    <link rel="stylesheet" href="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" media="all" type="text/css">
</head>
<body bgcolor="white">
<div class="layui-form" id="form">
    <div class="demoTable">
        <table class="layui-hide" id="demo" lay-filter="test"></table><script type="text/html" id="barDemo">
    </script>
    </div>
    <script src="../../layuiadmin/layui-v2.5.5/layui/layui.js" type="text/javascript">
    </script> <script type="text/javascript" src="../../layuiadmin/lib/jquery.min.js">
</script> <script type="text/javascript">
    var id=parent.PartitionId.empId;
    var parentData = id;
       var id1="";
        id1=parentData;
        function getId(){
            return id1;
        }
    layui.config({
        version: '1554901097999' //为了更新 js 缓存，可忽略
    });
    layui.use(['form','jquery','laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider','layedit',], function(){
        $=layui.jquery;
        var laypage = layui.laypage //分页
            ,layer = layui.layer //弹层
            ,form = layui.form
            ,layedit=layui.layedit
            ,table = layui.table //表格
            ,carousel = layui.carousel //轮播
            ,element = layui.element //元素操作
            ,slider = layui.slider //滑块
            ,laydate = layui.laydate
        //执行一个 table 实例
        table.render({
            elem: '#demo'
            ,url: 'http://localhost:8080/HrEmp/degreegetByid/'+id //数据接口
            ,title: '用户表'
            ,width:1300
            ,height:800
            ,method:'post'
            ,page: false //开启分页
            ,toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,totalRow: false //开启合计行
            ,cols: [[ //表头
                  {type:'checkbox',width:120,title:'全选', fixed: 'left'}
                            ,{field:'degreeId', width:80, title: '序号'}
                            ,{field:'degreeStartdate', width:140, title: '开始日期', sort: true}
                            ,{field:'degreeEnddate',title: '结束时间', width:140 }
                            ,{field:'degreeSchool',title:'毕业学校',width:100 }
                            ,{field:'degreeMajor',title:'主修专业',width:150 }
                            ,{field:'degreeEducation',title:'获得学历',width:130 }
                            ,{field:'degreeDegrees', width:120, title: '获得学位',}
                            ,{field:'degreeCrednum', width:110, title: '证书编号', sort: true}
                            ,{field:'degreeFulltime', width:100, title: '全日制', sort: true}
                            ,{field:'degreeSite', width:100, title: '所在地', sort: true}
            ]],
            id:"listData3"
        });


         //监听头工具栏事件
            table.on('toolbar(test)', function(obj){


                var checkStatus = table.checkStatus(obj.config.id)
                    ,data = checkStatus.data; //获取选中的数据
                var data = checkStatus.data;
                var str=[];
                if(data.length>0){
                    for(var i=0;i<data.length;i++){
                        str.push(data[i].degreeId);
                    }
                }
                var arr=str.join(",");
                switch(obj.event){
                    case 'add':
                             window.PartitionId=data;
                                           index=layer.open({
                                               type: 2,
                                               title: '添加教育经历',
                                               maxmin: true,
                                               shadeClose: true, //点击遮罩关闭层
                                               area : ['800px' , '520px'],
                                               content: 'hrdegreeadd.html',
                                           });
                                           layer.full(index);
                        break;
                    case 'update':
                          if(data.length === 0){
                              layer.msg('请选择一行');
                          } else if(data.length > 1){
                              layer.msg('只能同时编辑一个');
                          } else {
                              window.PartitionId=data;
                              index=layer.open({
                                  type: 2,
                                  title: '修改教育经历',
                                  maxmin: true,
                                  shadeClose: true, //点击遮罩关闭层
                                  area : ['800px' , '520px'],
                                  content: 'hrdegreeupdate.html',
                              });
                              layer.full(index);
                          }
                          break;
                    case 'delete':
                        if(data.length === 0){
                            layer.msg('请选择一行');
                        } else {
                            layer.msg('删除');
                            $.ajax({
                                type:"POST",
                                url:"http://localhost:8080/HrEmp/degreedel",
                                datatype:"json",
                                data:{
                                    id:arr,
                                },
                                async:true,
                                success:function(data){
                                    layui.table.reload('listData3');
                                },error:function(){
                                    alert("失败")
                                }
                            })
                        }
                        break;
                };
            });


        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                   ,layEvent = obj.event; //获得 lay-event 对应的值
            parentData =data;
            if(layEvent === 'detail'){
                window.PartitionId=data;
            }
        });
        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,skin: '#1E9FFF' //自定义选中色值
            //,skip: true //开启跳页
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页', {offset: 'b'});
                }
            }
        });
        var $ = layui.$, active = {
            reload: function(){
                //            var demoReload = $('#demoReload');
                //            var department = $('#department');
                //
                //执行重载
                table.reload('listData', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {

                    }
                });
            }
        };
        $(document).on("click",".layui-table-body table.layui-table tbody tr", function () {
            var index = $(this).attr('data-index');
            var tableBox = $(this).parents('.layui-table-box');
            //存在固定列
            if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length>0) {
                tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
            } else {
                tableDiv = tableBox.find(".layui-table-body.layui-table-main");
            }
            var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
            if (checkCell.length>0) {
                checkCell.click();
            }
        });

        $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
            e.stopPropagation();
        });
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</div>
</div>
</body>
</html>